/* Copyright (c) 2009-2010, Sean A.O. Harney <sharney3@gmail.com> */

#ifndef FUZZER_RANDOM_H
#define FUZZER_RANDOM_H



typedef enum { RS_DEV_URANDOM, RS_DEV_RANDOM, RS_LIBC_RAND_R } Random_src;

typedef struct {
    Random_src src;
    FILE *devfp;		/* /dev/random or /dev/urandom, if used */
    unsigned int rand_r_state;	/* used for the rand_r() to save state, if used */
} Random_handle;

#define PATH_DEV_RANDOM "/dev/random"
#define PATH_DEV_URANDOM "/dev/urandom"

#define RANDOM_DEFAULT_SRC RS_DEV_URANDOM
// default bounds (0,511) inclusive
#define RANDOM_LENGTH_DEFAULT_LB 0
#define RANDOM_LENGTH_DEFAULT_UB 511

/* prototypes */
bool random_init(Random_handle * handle, Random_src src);
void random_close(Random_handle * handle);
bool random_get_byte(Random_handle * handle, uint8_t * randbyte);
bool random_get_bytes(Random_handle * handle, uint8_t * randbytes,
		      size_t num_bytes);
bool random_get_random_amount_of_bytes(Random_handle * handle,
				       uint8_t * randbytes,
				       size_t * num_bytes, size_t lb,
				       size_t ub);

#endif				/* FUZZER_RANDOM_H */
